package JZ;

/**
 * @Classname JZ26
 * @Description // https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/ 树
 * @Date 2021/4/21 11:20
 * @Created by yin
 */
public class JZ26 {

    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) return false;
        return dfs(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }

    // 判断A为根节点的树是否包含B树
    public boolean dfs(TreeNode A, TreeNode B) {
        if (B == null) return true;
        if (A == null) return false;
        return A.val == B.val && dfs(A.left, B.left) && dfs(A.right, B.right);
    }
}
